1
|
|
|
/*jslint |
2
|
|
|
indent: 4 |
3
|
|
|
*/ |
4
|
|
|
|
5
|
|
|
/*global |
6
|
|
|
$, google, |
7
|
|
|
Cookies, Coordinates, IconFactory, Lines, |
8
|
|
|
id2alpha |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
function Marker(parent, id) { |
12
|
|
|
'use strict'; |
13
|
|
|
|
14
|
|
|
this.m_parent = parent; |
15
|
|
|
this.m_id = id; |
16
|
|
|
this.m_alpha = id2alpha(id); |
17
|
|
|
this.m_free = true; |
18
|
|
|
this.m_name = ""; |
19
|
|
|
var colors = ["FF0000", "00FF00", "0000FF", "FFFF00", "FF00FF", "00FFFF", "FFFFFF"]; |
20
|
|
|
this.m_color = colors[id % 7]; |
21
|
|
|
this.m_iconColor = ""; |
22
|
|
|
this.m_iconLabel = ""; |
23
|
|
|
this.m_miniIconUrl = ""; |
24
|
|
|
this.m_marker = null; |
25
|
|
|
this.m_circle = null; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
Marker.prototype.toString = function () { |
30
|
|
|
'use strict'; |
31
|
|
|
|
32
|
|
|
return this.getAlpha() + ":" + |
33
|
|
|
this.getPosition().lat().toFixed(6) + ":" + |
34
|
|
|
this.getPosition().lng().toFixed(6) + ":" + |
35
|
|
|
this.getRadius() + ":" + |
36
|
|
|
this.getName() + ":" + |
37
|
|
|
this.m_color; |
38
|
|
|
}; |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
Marker.prototype.toXmlWpt = function () { |
42
|
|
|
'use strict'; |
43
|
|
|
|
44
|
|
|
var data = ''; |
45
|
|
|
data += '<wpt lat="' + this.getPosition().lat().toFixed(8) + '" lon="' + this.getPosition().lng().toFixed(8) + '">\n'; |
46
|
|
|
data += ' <name>' + this.getName() + '</name>\n'; |
47
|
|
|
data += ' <sym>flag</sym>\n'; |
48
|
|
|
if (this.getRadius() > 0) { |
49
|
|
|
data += ' <extensions>\n'; |
50
|
|
|
data += ' <wptx1:WaypointExtension>\n'; |
51
|
|
|
data += ' <wptx1:Proximity>' + this.getRadius() + '</wptx1:Proximity>\n'; |
52
|
|
|
data += ' </wptx1:WaypointExtension>\n'; |
53
|
|
|
data += ' </extensions>\n'; |
54
|
|
|
} |
55
|
|
|
data += '</wpt>'; |
56
|
|
|
|
57
|
|
|
return data; |
58
|
|
|
}; |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
Marker.prototype.isFree = function () { |
62
|
|
|
'use strict'; |
63
|
|
|
|
64
|
|
|
return this.m_free; |
65
|
|
|
}; |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
Marker.prototype.clear = function () { |
69
|
|
|
'use strict'; |
70
|
|
|
|
71
|
|
|
if (this.m_free) { |
72
|
|
|
return; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
this.m_free = true; |
76
|
|
|
this.m_marker.setMap(null); |
77
|
|
|
this.m_marker = null; |
78
|
|
|
this.m_circle.setMap(null); |
79
|
|
|
this.m_circle = null; |
80
|
|
|
var colors = ["FF0000", "00FF00", "0000FF", "FFFF00", "FF00FF", "00FFFF", "FFFFFF"]; |
81
|
|
|
this.m_color = colors[this.m_id % 7]; |
82
|
|
|
this.m_iconColor = ""; |
83
|
|
|
this.m_iconLabel = ""; |
84
|
|
|
|
85
|
|
|
$('#dyn' + this.m_id).remove(); |
86
|
|
|
|
87
|
|
|
Lines.updateLinesMarkerRemoved(this.m_id); |
88
|
|
|
this.m_parent.handleMarkerCleared(); |
89
|
|
|
}; |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
Marker.prototype.getId = function () { |
93
|
|
|
'use strict'; |
94
|
|
|
|
95
|
|
|
return this.m_id; |
96
|
|
|
}; |
97
|
|
|
|
98
|
|
|
|
99
|
|
|
Marker.prototype.getAlpha = function () { |
100
|
|
|
'use strict'; |
101
|
|
|
|
102
|
|
|
return this.m_alpha; |
103
|
|
|
}; |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
Marker.prototype.getName = function () { |
107
|
|
|
'use strict'; |
108
|
|
|
|
109
|
|
|
return this.m_name; |
110
|
|
|
}; |
111
|
|
|
|
112
|
|
|
|
113
|
|
|
Marker.prototype.setName = function (name) { |
114
|
|
|
'use strict'; |
115
|
|
|
|
116
|
|
|
this.m_name = name; |
117
|
|
|
this.update(); |
118
|
|
|
}; |
119
|
|
|
|
120
|
|
|
|
121
|
|
|
Marker.prototype.setPosition = function (position) { |
122
|
|
|
'use strict'; |
123
|
|
|
|
124
|
|
|
this.m_marker.setPosition(position); |
125
|
|
|
this.m_circle.setCenter(position); |
126
|
|
|
this.update(); |
127
|
|
|
}; |
128
|
|
|
|
129
|
|
|
|
130
|
|
|
Marker.prototype.getPosition = function () { |
131
|
|
|
'use strict'; |
132
|
|
|
|
133
|
|
|
return this.m_marker.getPosition(); |
134
|
|
|
}; |
135
|
|
|
|
136
|
|
|
|
137
|
|
|
Marker.prototype.setRadius = function (radius) { |
138
|
|
|
'use strict'; |
139
|
|
|
|
140
|
|
|
this.m_circle.setRadius(radius); |
141
|
|
|
this.update(); |
142
|
|
|
}; |
143
|
|
|
|
144
|
|
|
|
145
|
|
|
Marker.prototype.getRadius = function () { |
146
|
|
|
'use strict'; |
147
|
|
|
|
148
|
|
|
return this.m_circle.getRadius(); |
149
|
|
|
}; |
150
|
|
|
|
151
|
|
|
|
152
|
|
|
Marker.prototype.setNamePositionRadiusColor = function (name, position, radius, color) { |
153
|
|
|
'use strict'; |
154
|
|
|
|
155
|
|
|
this.m_name = name; |
156
|
|
|
this.m_marker.setPosition(position); |
157
|
|
|
this.m_circle.setCenter(position); |
158
|
|
|
this.m_circle.setRadius(radius); |
159
|
|
|
this.m_color = color; |
160
|
|
|
this.update(); |
161
|
|
|
}; |
162
|
|
|
|
163
|
|
|
|
164
|
|
|
Marker.prototype.initialize = function (map, name, position, radius, color) { |
165
|
|
|
'use strict'; |
166
|
|
|
|
167
|
|
|
this.m_free = false; |
168
|
|
|
this.m_name = name; |
169
|
|
|
if (color !== "") { |
170
|
|
|
this.m_color = color; |
171
|
|
|
} |
172
|
|
|
this.m_iconLabel = name; |
173
|
|
|
this.m_iconColor = this.m_color; |
174
|
|
|
|
175
|
|
|
var self = this; |
176
|
|
|
|
177
|
|
|
this.m_miniIcon = IconFactory.createMiniIcon(this.m_alpha, this.m_color); |
178
|
|
|
|
179
|
|
|
this.m_marker = new google.maps.Marker({ |
180
|
|
|
position: position, |
181
|
|
|
map: map, |
182
|
|
|
icon: IconFactory.createMapIcon(this.m_name, this.m_color), |
183
|
|
|
optimized: false, |
184
|
|
|
draggable: true |
185
|
|
|
}); |
186
|
|
|
|
187
|
|
|
google.maps.event.addListener(this.m_marker, "drag", function () { |
188
|
|
|
self.update(); |
189
|
|
|
}); |
190
|
|
|
google.maps.event.addListener(this.m_marker, "dragend", function () { |
191
|
|
|
self.update(); |
192
|
|
|
}); |
193
|
|
|
|
194
|
|
|
this.m_circle = new google.maps.Circle({ |
195
|
|
|
center: position, |
196
|
|
|
map: map, |
197
|
|
|
strokeColor: "#" + this.m_color, |
198
|
|
|
strokeOpacity: 1, |
199
|
|
|
fillColor: "#" + this.m_color, |
200
|
|
|
fillOpacity: 0.25, |
201
|
|
|
strokeWeight: 1, |
202
|
|
|
radius: radius |
203
|
|
|
}); |
204
|
|
|
}; |
205
|
|
|
|
206
|
|
|
|
207
|
|
|
Marker.prototype.update = function () { |
208
|
|
|
'use strict'; |
209
|
|
|
|
210
|
|
|
if (this.m_free) { |
211
|
|
|
return; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
var pos = this.m_marker.getPosition(), |
215
|
|
|
radius = this.m_circle.getRadius(); |
216
|
|
|
|
217
|
|
|
this.m_circle.setCenter(pos); |
218
|
|
|
|
219
|
|
|
Cookies.set('marker' + this.m_id, pos.lat().toFixed(6) + ":" + pos.lng().toFixed(6) + ":" + radius + ":" + this.m_name + ":" + this.m_color, {expires: 30}); |
220
|
|
|
$('#dyn' + this.m_id + ' > .view .name').html(this.m_name); |
221
|
|
|
$('#dyn' + this.m_id + ' > .view .coords').html(Coordinates.toString(pos)); |
222
|
|
|
$('#dyn' + this.m_id + ' > .view .radius').html(radius); |
223
|
|
|
$('#dyn' + this.m_id + ' > .edit .name').val(this.m_name); |
224
|
|
|
$('#dyn' + this.m_id + ' > .edit .coords').val(Coordinates.toString(pos)); |
225
|
|
|
$('#dyn' + this.m_id + ' > .edit .radius').val(radius); |
226
|
|
|
$('#dyn' + this.m_id + ' > .edit .color').val(this.m_color); |
227
|
|
|
|
228
|
|
|
if ((this.m_iconLabel !== this.m_name) || (this.m_iconColor !== this.m_color)) { |
229
|
|
|
this.m_iconLabel = this.m_name; |
230
|
|
|
this.m_iconColor = this.m_color; |
231
|
|
|
this.m_marker.setIcon(IconFactory.createMapIcon(this.m_name, this.m_color)); |
232
|
|
|
this.m_miniIcon = IconFactory.createMiniIcon(this.m_alpha, this.m_color); |
233
|
|
|
this.m_circle.setOptions({strokeColor: "#" + this.m_color, fillColor: "#" + this.m_color}); |
234
|
|
|
} |
235
|
|
|
$('#dyn' + this.m_id + ' > .view .icon').attr("src", this.m_miniIcon.url); |
236
|
|
|
$('#dyn' + this.m_id + ' > .view .icon').attr("style", "width: " + this.m_miniIcon.width + "px; height: " + this.m_miniIcon.height + "px;"); |
237
|
|
|
|
238
|
|
|
Lines.updateLinesMarkerMoved(this.m_id); |
239
|
|
|
}; |
240
|
|
|
|